#####################################################
#                                                   #
#  AlgorithmTask Class:                             # 
#                                                   #
#  An algorithm task defines two things:            #
#  1. 'text' associated with this algorithm task    #
#  2. constraints for this algorithm task           #
#                                                   #
#  A constraint may be, that in a particular task   # 
#  within an algorithm, a task may only be dragged  #
#  from a certain data structure to another         #
#  defined data structure.                          #
#                                                   #
#  Example: constraints={'DS1': ['DS2','DS3']}      #
#                                                   # 
#  Meaning: in this algorithm step, only tasks      #
#           from DS1 may be moved to either         #
#           DS2 or DS3 (not vice-versa)             #
#                                                   #
#  Author: Felix Rohrer                             #     
#  Course: CS MET 575                               #
#  Year:   2011                                     #
#                                                   #
#####################################################

class AlgorithmTask():
  def __init__(self, text, constraints={}):
    self.text = text
    self.constraints = constraints

  # checks if the provided source and destination
  # of the current task does not violate an algorithm constraint
  # if violation, return False, otherwise return True

  # example1: constraints={'READY':None} -> task from READY allowed to anywhere
  # example2: constraints={'READY':['CPU','BLOCKED']} -> task from READY allowed
  #           to move to CPU or BLOCKED
  def checkConstraint(self, fromDS, toDS):
    if fromDS in self.constraints:
      # a task may be allowed to move from a given position
      # fromDS to any other position (indicated by None)
      if self.constraints[fromDS] == None or toDS in self.constraints[fromDS]:
        return True
    return False

  # get the text associated with this algorithm task
  def getAlgText(self):
    return self.text
